
/* The gift is selected or not 
 **/
function isSelectedGift(gift){
    var flag = getIdGift(gift);
    if (flag == -1)
        return false;
    else 
        return true;
}

/**
 * Show dialog, a list of friends
 * Refer at: http://developers.facebook.com/docs/reference/dialogs/requests/
 */
function fbInviteFriends(invite_title, invite_message, id_page) 
{   
    id_gift = $('.tab_selected_gift_image.active').attr('value'); 
    if (id_gift == undefined) {
        alert('Please, select a gift before sending!');
        return false;        
    }
    FB.ui({
            method: 'apprequests',
            title: invite_title,
            message: invite_message,
            data:{
                'id_page':id_page
            }
        },function(response){
            console.log(response);
            if (response != null) {                            
                submitMessageContent(response, id_gift);                        
            }
    });
    return true;
}

function sendRequestToRecipient(receiver_id) {   
    FB.ui({
            method: 'apprequests', 
            message: 'sendRequestToRecipient',
            to: receiver_id
        }, callbackGetResponse);   
}

function callbackGetResponse(response){             
}

function submitMessageContent(response,id_gift) {    
    document.getElementById('id_receivers').value = response.to;//Array - list of friends    
    document.getElementById('id_request').value = response.request;    
    document.getElementById('id_gift').value = id_gift
    document.forms['form_compose_message'].submit();
}